package co.fitstart.entity.content;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 新闻
 * @author Leo
 */
@Entity
@Table(name="content_news")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class News {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 新闻名称 */
    private String name;
    
    /** 新闻简介 */
    private String summary;
    
    /** 新闻封面 */
    private String cover;
    
    /** 新闻链接 */
    private String link;
    
    @JSONField(format = "yyyy-MM-dd")
    private Date createTime;
    
    @JSONField(serialize = false)
    private Date lastUpdateTime;
    
    /** 置顶序号 默认100 */
    private int serial;
    
    @Column(name = "is_disabled")
    @JSONField(serialize = false)
    private boolean disabled;
    
    /**
     * default constructor
     * 
     */
    public News() {
        
    }
    
    /**
     * initialize news basic fields
     * 
     * @return
     */
    public News initialize() {
        this.serial = 100;
        this.createTime = new Date();
        this.lastUpdateTime = this.createTime;
        return this;
    }
    
    /**
     * Down news serial
     * 
     * @return
     */
    public News unstick() {
        this.serial = 100;
        this.lastUpdateTime = new Date();
        return this;
    }
    
    /**
     * Up news serial
     * 
     * @param serial
     * @return
     */
    public News stick(int serial) {
        this.serial = serial + 1;
        this.lastUpdateTime = new Date();
        return this;
    }
    
    /**
     * Disabled news
     * 
     * @return
     */
    public News disable() {
        this.disabled = true;
        return this;
    }
    
    /**
     * edit news cover
     * 
     * @param cover
     * @return
     */
    public News editCover(String cover) {
        this.cover = cover;
        this.lastUpdateTime = new Date();
        return this;
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the summary
     */
    public String getSummary() {
        return summary;
    }

    /**
     * @return the cover
     */
    public String getCover() {
        return cover;
    }
    
    /**
     * @return the link
     */
    public String getLink() {
        return link;
    }
    
    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }
    
    /**
     * @return the lastUpdateTime
     */
    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    /**
     * @return the serial
     */
    public int getSerial() {
        return serial;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param summary the summary to set
     */
    public void setSummary(String summary) {
        this.summary = summary;
    }

    /**
     * @param cover the cover to set
     */
    public void setCover(String cover) {
        this.cover = cover;
    }
    
    /**
     * @param link the link to set
     */
    public void setLink(String link) {
        this.link = link;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    
    /**
     * @param lastUpdateTime the lastUpdateTime to set
     */
    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    /**
     * @param serial the serial to set
     */
    public void setSerial(int serial) {
        this.serial = serial;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}